package com.lj.hadoop;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.lib.db.DBWritable;

/**
 * 这是一个自定义的连接数据库的类，
 * 主要是能够通过mapperreduce来访问mysql等数据库
 * 参考网址：
 * http://zhidao.baidu.com/link?url=AXkSlOJin0202hMoFmc0aWY6bA5a6vYUh9z4Ojr1piOWko5YhrZFMucmTkj0n3ATCyH7Fn7WVL_vWFB86o5FAHga2FCtU4E3lG_xuC_zbNy
 * 
 * 
 * @author Administrator
 *
 */
public class DSDATAUSERRecord implements Writable,DBWritable{
	private int id;
	private String user_name;
	private String password;
	private String district_name;
	private String start_audit;
	private String end_audit;
	private String description;
	private String upper_district;
	

	@Override
	public void write(PreparedStatement statement) throws SQLException {
		// 设置字段信息
		statement.setLong(1, this.id);
		statement.setString(2, this.user_name);
		statement.setString(3, this.password);
		statement.setString(4, this.district_name);
		statement.setString(5, this.start_audit);
		statement.setString(6, this.end_audit);
		statement.setString(7, this.description);
		statement.setString(8, this.upper_district);
		
	}

	@Override
	public void readFields(ResultSet resultSet) throws SQLException {
		// TODO Auto-generated method stub
		this.id = resultSet.getInt(1);
		this.user_name = resultSet.getString(2);
		this.password = resultSet.getString(3);
		this.district_name = resultSet.getString(4);
		this.start_audit = resultSet.getString(5);
		this.end_audit = resultSet.getString(6);
		this.description = resultSet.getString(7);
		this.upper_district = resultSet.getString(8);
		
		
	}

	@Override
	public void write(DataOutput out) throws IOException {
		// TODO Auto-generated method stub
		out.writeInt(id);
		Text.writeString(out, this.user_name);
		Text.writeString(out, this.password);
		Text.writeString(out, this.district_name);
		Text.writeString(out, this.start_audit);
		Text.writeString(out, this.end_audit);
		Text.writeString(out, this.description);
		Text.writeString(out, this.upper_district);
		
		
	}

	@Override
	public void readFields(DataInput in) throws IOException {
		// TODO Auto-generated method stub
		this.id = in.readInt();
		this.user_name = Text.readString(in);
		this.password = Text.readString(in);
		this.district_name = Text.readString(in);
		this.start_audit = Text.readString(in);
		this.end_audit = Text.readString(in);
		this.description = Text.readString(in);
		this.upper_district = Text.readString(in);
		
	}

	/**
	 * 这里重写toString，主要是能够以固定的格式去在hadoop中保存文件
	 */
	@Override
	public String toString() {
		return "id:" + id + " user_name:" + user_name
				+ " password:" + password + " district_name:" + district_name
				+ " start_audit:" + start_audit + " end_audit:" + end_audit
				+ " description:" + description + " upper_district:"
				+ upper_district;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUser_name() {
		return user_name;
	}

	public void setUser_name(String user_name) {
		this.user_name = user_name;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getDistrict_name() {
		return district_name;
	}

	public void setDistrict_name(String district_name) {
		this.district_name = district_name;
	}

	public String getStart_audit() {
		return start_audit;
	}

	public void setStart_audit(String start_audit) {
		this.start_audit = start_audit;
	}

	public String getEnd_audit() {
		return end_audit;
	}

	public void setEnd_audit(String end_audit) {
		this.end_audit = end_audit;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getUpper_district() {
		return upper_district;
	}

	public void setUpper_district(String upper_district) {
		this.upper_district = upper_district;
	}
	
	
	
	

}
